﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dhtl.Service.IService;
using DataBase.Daihoctuonglai;
using Dhtl_Repositry.Repository;

namespace Dhtl.Service.Service
{
    public class Service_User : IUser
    {

        public int addOrupdate(Usser entity)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                return userResp.CreateOrUpdate(entity);
            }
        }

        public void delete(int id)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                userResp.Delete(id);
            }
        }

        public void deleteByName(string Name)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                userResp.DeleteByName(Name);
            }
        }


        public Usser GetById(int id)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                return userResp.GetById(id);
            }
        }

        public Usser GetByEmail(string email)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                return userResp.GetUserByEmail(email);
            }
        }

        public bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                return userResp.ChangePassword(username, oldPassword, newPassword);
            }
        }

        public bool ValidateUser(string username, string password)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
              var entity =  userResp.LogIn(username, password);
              if (entity != null)
                  return true;
              else return false;
            }
        }

       

        public Usser LogIn(string username, string Password)
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                return userResp.LogIn(username,Password);
            }
        }

        public List<Usser> List()
        {
            using (UserRepositry userResp = new UserRepositry())
            {
                return userResp.List();
            }
        }
    }
}
